#include "PrecompiledHeaders.h"
#include "MenuCredits.h"


void MenuCredits::enter(void)
{
    // set cameras to render through
    resources->render_window->getViewport(0)->setCamera(resources->main_gui_camera);
    if(resources->config->isTriScreen())
    {
        resources->render_window->getViewport(1)->setCamera(resources->left_gui_camera);
        resources->render_window->getViewport(2)->setCamera(resources->right_gui_camera);
    }
    
    // Shows mouse
    CEGUI::MouseCursor::getSingleton().show();
    
    // Load the layout
    CEGUI::Window* CreditsSheet = CEGUI::WindowManager::getSingletonPtr()->loadWindowLayout("Credits.layout");
    resources->GUISystem->setGUISheet(CreditsSheet);
    
    // Subscribe the continue button
    subscribeButton("Credits/BackButton", &MenuCredits::clickBackButton,
                                             &MenuCredits::hoverBackButton,
                                             &MenuCredits::offBackButton);
	// Initialises the menu index
    winIterator = activeWindows.begin();
}

void MenuCredits::resume(void)
{
    popGameState();
}

void MenuCredits::exit(void)
{
    CEGUI::MouseCursor::getSingleton().hide();
    CEGUI::WindowManager::getSingleton().destroyAllWindows();
	activeWindows.clear();
}

bool MenuCredits::clickBackButton(const CEGUI::EventArgs &e)
{
    resources->audio->playSource(AUDIO_MENU_CLICK);
	unsubscribeButton("Credits/BackButton");
    popGameState();
    return true;
}

bool MenuCredits::hoverBackButton(const CEGUI::EventArgs &e)
{
    resources->audio->playSource(AUDIO_MENU_OVER);
    setWindowText("Credits/BackButton", "[continue]");
    return true;
}

bool MenuCredits::offBackButton(const CEGUI::EventArgs &e)
{
    setWindowText("Credits/BackButton", "continue");
    return true;
}

bool MenuCredits::hoverNoise(const CEGUI::EventArgs &e)
{
    resources->audio->playSource(AUDIO_MENU_OVER);
    return true;
}
